import {mapGetters} from 'vuex'
export default {
  onShow() {
    this.setBadge()
  },
  computed: {
    ...mapGetters('cartAbout', ['total'])
  },
  methods: {
    // 设置数字徽标
    setBadge() {
      if (this.total === 0) return
      uni.setTabBarBadge({
        index: 2,
        text: this.total + ''
      })
    }
  },
  // 监听购物车数量更新徽标
  watch: {
    total: {
      immediate: true,
      handler(value) {
        if (value == 0) return uni.removeTabBarBadge({index: 2})
        this.setBadge();
      }
    }
  }
}